package com.yanqu.road.logic.sort;

import com.yanqu.road.entity.rank.UserRank;

import java.util.Comparator;
import java.util.Objects;

public class SeacraftPirateRiotChapterRankSort implements Comparator<UserRank> {

    @Override
    public int compare(UserRank o1, UserRank o2) {
        if (Objects.equals(o1.getParam(), "")) {
            o1.setParam("0");
        }
        if (Objects.equals(o2.getParam(), "")) {
            o2.setParam("0");
        }
        int chapterId1 = Integer.valueOf(o1.getParam());
        int chapterId2 = Integer.valueOf(o2.getParam());

        int result = chapterId2 - chapterId1;
        if (result != 0) {
            return result > 0 ? 1 : -1;
        }

        result = o2.getValue().compareTo(o1.getValue());
        if (result != 0) {
            return result;
        }

        return Long.compare(o1.getLastUpdateTime(), o2.getLastUpdateTime());
    }
}
